// pages/index/Mymessage/message.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: "",
    joinDialog: true,
    //图片
    mylist: {
      username: "",
    },
    fileList: "",
    myfileList: [{
      url: "",
      isImage: true,
    }],
    location: "",
    replenish: "",
    detailed: "",
    status:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //调用弹窗组件
    this.dialog = this.selectComponent("#dialog");

  },
  _success() {
    this.dialog.hidedialog();
    this.setData({
      joinDialog: true,
    })
  },
  delete(event) {
    this.setData({
      fileList: ""
    })
  },
  afterRead(event) {
    let that = this
    that.data.myfileList[0] = event.detail.file
    console.log(event.detail.file.path)
    this.setData({
      fileList: that.data.myfileList
    })
    // console.log(event.detail)
    // const { file } = event.detail;
    // // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    // wx.uploadFile({
    //   method:"POST",
    //   url: 'http://192.168.19.114:8080/blm_war_exploded/toBeBusiness', 
    //   filePath: file.path,
    //   name: 'file',
    //   formData: { user: 'test' },
    //   success(res) {
    //     // 上传完成需要更新 fileList
    //     // const { fileList = [] } = this.data;
    //     // fileList.push({ ...file, url: res.data });
    //     // this.setData({ fileList });
    //   },
    // });
  },
  map: function () {

    var that = this
    wx.chooseLocation({
      success: function (res) {
        // success
        that.setData({
          location: res.name
        })

      },
    })
  },
  replenish(e) {

    this.setData({
      replenish: e.detail
    })
  },
  detailed(e) {
    this.setData({
      detailed: e.detail
    })
  },

  join: function () {

    let that = this
    const file = that.data.myfileList
    console.log(file[0].path)

    wx.uploadFile({
      url: 'http://192.168.19.114:8080/blm_war_exploded/toBeBusiness',
      filePath: file[0].path,
      name: 'file',
      formData: {
        id: 23,
        sAddress: that.data.location,
        sDetailedAddress: that.data.detailed,
        sName: that.data.replenish,
      },
      success(res) {
        console.log(res)
      let parems=JSON.parse(res.data)
               console.log(parems);
               
        if (parems.status == "1") {
          that.dialog.showdialog();
          that.setData({
            joinDialog: false,
            state: "提交成功,请您等待审核"
          })
        } else if (parems.status == "0") {
          that.dialog.showdialog();
          that.setData({
            joinDialog: false,
            state: "提交失败"
          })
        } else if (parems.status == "-1") {
          that.dialog.showdialog();
          that.setData({
            joinDialog: false,
            state: "文件过大，请缩小后再提交"
          })
        } else if(parems.status == "2") {
          that.dialog.showdialog();
          that.setData({
            joinDialog: false,
            state: "您已提交，请勿重复操作"
          })
        }else{
          that.dialog.showdialog();
          that.setData({
            joinDialog: false,
            state: "系统繁忙"
          })
        }
      }
    })




  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})